//
//  main.m
//  fileManagerDemo
//
//  Created by zhouxiaobo on 15/10/29.
//  Copyright © 2015年 mapath. All rights reserved.
//

#import <Foundation/Foundation.h>

#define PATH @"/Users/zhouxiaobo/Documents/Temps"

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        NSFileManager *fm = [NSFileManager defaultManager];
        
        NSError *error;
        
        //1. 列目录
        NSArray *arr = [fm contentsOfDirectoryAtPath:PATH error:&error];
        //NSLog(@"%@",arr);
        
        //2. 列目录带下面的子目录
        NSArray *subArr = [fm subpathsOfDirectoryAtPath:PATH error:&error];
        //NSLog(@"%@",subArr);
        
        //3. 新建目录
//        BOOL flag = [fm createDirectoryAtPath:[NSString stringWithFormat:@"%@/dir/temp",PATH] withIntermediateDirectories:TRUE attributes:nil error:&error];
//        
//        if (flag) {
//            NSLog(@"新建文件夹成功！");
//        }else{
//            NSLog(@"%@",[error description]);
//        }
        
        //4. 新建文件
//        BOOL flag1 = [fm createFileAtPath:[NSString stringWithFormat:@"%@/dir/temp/hello.txt",PATH] contents:[@"hello world" dataUsingEncoding:NSUTF8StringEncoding] attributes:nil];
//        if (flag1) {
//            NSLog(@"新建文件成功！");
//        }else{
//            NSLog(@"%@",[error description]);
//        }
        
        //5. 删除文件
        BOOL flag2 = [fm removeItemAtPath:[NSString stringWithFormat:@"%@/dir/temp/hello.txt",PATH] error:&error];
        if (flag2) {
            NSLog(@"删除文件成功！");
        }else{
            NSLog(@"%@",[error description]);
        }
                      
        
    }
    return 0;
}
